ARG basetag="450-signed-ubuntu22.04"  # Ubuntu only
FROM nvcr.io/nvidia/driver:"${basetag}"

ENV NVIDIA_DISABLE_REQUIRE=true
ENV DEBIAN_FRONTEND=noninteractive

# Update APT sources
RUN . /etc/os-release && [ "${NAME}" = "Ubuntu" ] && \
  echo "deb [arch=amd64] http://archive.ubuntu.com/ubuntu ${UBUNTU_CODENAME} main universe" > /etc/apt/sources.list && \
  echo "deb [arch=amd64] http://archive.ubuntu.com/ubuntu ${UBUNTU_CODENAME}-updates main universe" >> /etc/apt/sources.list && \
  echo "deb [arch=amd64] http://archive.ubuntu.com/ubuntu ${UBUNTU_CODENAME}-security main universe" >> /etc/apt/sources.list

# Install Python 3
RUN apt-get update && \
  apt-get install --quiet --yes --no-install-recommends python3-dev python3-venv python3-pip locales && \
  rm -rf /var/lib/apt/lists/*

# Setup locale
ENV LC_ALL=C.UTF-8
RUN update-locale LC_ALL="C.UTF-8"

# Setup environment
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple &&\
  pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn &&\
  pip install --upgrade pip setuptools && \
  rm -rf /root/.cache

COPY . /nvitop
WORKDIR /nvitop
RUN pip install . && \
  pip install pipx && \
  #pipx install nvitop-exporter &&\
  #pipx ensurepath &&\
  rm -rf /root/.cache

# Entrypoint
#ENTRYPOINT [ "/venv/bin/python3", "-m", "nvitop" ]
EXPOSE 5050
ENTRYPOINT ["/nvitop/entrypoint.sh"]
